﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="IndexOM.aspx.cs" Inherits="DATN.mds.OpportunityManagement.IndexOM" MasterPageFile="~/InternalSite.Master" %>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent1" runat="server">

<script type="text/javascript">
    //Reference of the GridView. 
    var TargetBaseControl = null;
    //Total no of checkboxes in a particular column inside the GridView.
    var CheckBoxes;
    //Total no of checked checkboxes in a particular column inside the GridView.
    var CheckedCheckBoxes;
    //Array of selected item's Ids.
    var SelectedItems;
    //Hidden field that wil contain string of selected item's Ids separated by '|'.
    var SelectedValues;

    window.onload = function () {
        //Get reference of the GridView. 
        try {
            TargetBaseControl = document.getElementById('<%= this.GridView1.ClientID %>');
        }
        catch (err) {
            TargetBaseControl = null;
        }

        //Get total no of checkboxes in a particular column inside the GridView.
        try {
            CheckBoxes = parseInt('<%= this.GridView1.Rows.Count %>');
        }
        catch (err) {
            CheckBoxes = 0;
        }

        //Get total no of checked checkboxes in a particular column inside the GridView.
        CheckedCheckBoxes = 0;

        //Get hidden field that wil contain string of selected item's Ids separated by '|'.
        SelectedValues = document.getElementById('<%= this.hdnFldSelectedValues.ClientID %>');

        //Get an array of selected item's Ids.
        if (SelectedValues.value == '')
            SelectedItems = new Array();
        else
            SelectedItems = SelectedValues.value.split('|');

        //Restore selected CheckBoxes' states.
        if (TargetBaseControl != null)
            RestoreState();
    }

    function HeaderClick(CheckBox) {
        //Get all the control of the type INPUT in the base control.
        var Inputs = TargetBaseControl.getElementsByTagName('input');

        //Checked/Unchecked all the checkBoxes in side the GridView & modify selected items array.
        for (var n = 0; n < Inputs.length; ++n)
            if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf('chkBxSelect', 0) >= 0) {
                Inputs[n].checked = CheckBox.checked;
                if (CheckBox.checked)
                    SelectedItems.push(document.getElementById(Inputs[n].id.replace('chkBxSelect', 'hdnFldId')).value);
                else
                    DeleteItem(document.getElementById(Inputs[n].id.replace('chkBxSelect', 'hdnFldId')).value);
            }

        //Update Selected Values. 
        SelectedValues.value = SelectedItems.join('|');

        //Reset Counter
        CheckedCheckBoxes = CheckBox.checked ? CheckBoxes : 0;
    }

    function ChildClick(CheckBox, HCheckBox, Id) {
        //Modifiy Counter;            
        if (CheckBox.checked && CheckedCheckBoxes < CheckBoxes)
            CheckedCheckBoxes++;
        else if (CheckedCheckBoxes > 0)
            CheckedCheckBoxes--;

        //Change state of the header CheckBox.
        if (CheckedCheckBoxes < CheckBoxes)
            HCheckBox.checked = false;
        else if (CheckedCheckBoxes == CheckBoxes)
            HCheckBox.checked = true;

        //Modify selected items array.
        if (CheckBox.checked)
            SelectedItems.push(Id);
        else
            DeleteItem(Id);

        //Update Selected Values. 
        SelectedValues.value = SelectedItems.join('|');
    }

    function RestoreState() {
        //Get all the control of the type INPUT in the base control.
        var Inputs = TargetBaseControl.getElementsByTagName('input');

        //Header CheckBox
        var HCheckBox = null;

        //Restore previous state of the all checkBoxes in side the GridView.
        for (var n = 0; n < Inputs.length; ++n)
            if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf('chkBxSelect', 0) >= 0)
                if (IsItemExists(document.getElementById(Inputs[n].id.replace('chkBxSelect', 'hdnFldId')).value) > -1) {
                    Inputs[n].checked = true;
                    CheckedCheckBoxes++;
                }
                else
                    Inputs[n].checked = false;
            else if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf('chkBxHeader', 0) >= 0)
                HCheckBox = Inputs[n];

        //Change state of the header CheckBox.
        if (CheckedCheckBoxes < CheckBoxes)
            HCheckBox.checked = false;
        else if (CheckedCheckBoxes == CheckBoxes)
            HCheckBox.checked = true;
    }

    function DeleteItem(Text) {
        var n = IsItemExists(Text);
        if (n > -1)
            SelectedItems.splice(n, 1);
    }

    function IsItemExists(Text) {
        for (var n = 0; n < SelectedItems.length; ++n)
            if (SelectedItems[n] == Text)
                return n;

        return -1;
    }     
    </script>

</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent2" runat="server">

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="MainContent3" runat="server">

<div id="contentx" class="clearingfix">    
              <br/>
              <center> <h3>Quản lý Cơ Hội</h3> </center>
               <hr/>
               <div class="floatboxx">

    <asp:GridView ID="GridView1" runat="server" 
        CellPadding="3" ForeColor="Black" DataKeyNames="Opp_Id"
        GridLines="Vertical" onrowcommand="GridView1_RowCommand" AllowPaging="True" 
        RowStyle-CssClass = "Grd_Row"
        onpageindexchanging="GridView1_PageIndexChanging"
        AutoGenerateColumns ="False" BackColor="White" BorderColor="#999999" 
        BorderStyle="Solid" BorderWidth="1px" 
        onrowdatabound="GridView1_RowDataBound" EmptyDataText ="Không có dữ liệu nào phù hợp"
        onrowdeleting="GridView1_RowDeleting">
        <AlternatingRowStyle BackColor="#CCCCCC" />
        <FooterStyle BackColor="#CCCCCC" />
        <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
        <SortedAscendingCellStyle BackColor="#F1F1F1" />
        <SortedAscendingHeaderStyle BackColor="#808080" />
        <SortedDescendingCellStyle BackColor="#CAC9C9" />
        <SortedDescendingHeaderStyle BackColor="#383838" />


        <Columns>
         <asp:TemplateField HeaderText="">
                     <ItemTemplate>
                        <asp:CheckBox ID="chkBxSelect" runat="server" />
                        <asp:HiddenField ID="hdnFldId" runat="server" Value='<%# Eval("Opp_Id") %>' />
                     </ItemTemplate>
                     <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
                     <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
                     <HeaderTemplate>
                        <center><asp:CheckBox ID="chkBxHeader" onclick="javascript:HeaderClick(this);" runat="server" />
                        </center>
                     </HeaderTemplate>
                  </asp:TemplateField>

            <asp:BoundField DataField="Name" HeaderText="Tên"/>
            <asp:BoundField DataField="DateStart" HeaderText="Ngày B&#7855;t &#272;&#7847;u"
                            DataFormatString="{0:dd'/'MM'/'yyyy}"  HeaderStyle-Width ="120" 
                            HeaderStyle-VerticalAlign ="Middle">
<HeaderStyle VerticalAlign="Middle" Width="110px"></HeaderStyle>
            </asp:BoundField>
            <asp:BoundField DataField="DateClose" HeaderText="Ngày K&#7871;t Thúc"
                            DataFormatString="{0:dd'/'MM'/'yyyy}"  HeaderStyle-Width ="110"
                            HeaderStyle-VerticalAlign ="Middle">
<HeaderStyle VerticalAlign="Middle" Width="110px"></HeaderStyle>
            </asp:BoundField>
            <asp:BoundField DataField="DateCreate" HeaderText="Ngày T&#7841;o"
                            DataFormatString="{0:dd'/'MM'/'yyyy}"  HeaderStyle-Width ="110"
                            HeaderStyle-VerticalAlign ="Middle">
<HeaderStyle VerticalAlign="Middle" Width="110px"></HeaderStyle>
            </asp:BoundField>
            <asp:BoundField DataField="Status" HeaderText="Tình Tr&#7841;ng" >
            </asp:BoundField>
            <asp:BoundField DataField="EstimatesFund" HeaderText ="S&#7889; V&#7889;n"
            HeaderStyle-Width="100" DataFormatString="{0:0,0 (VND)}">    
            </asp:BoundField>
            <asp:BoundField DataField="EstimatesProfit" HeaderText ="S&#7889; Lãi"
            HeaderStyle-Width="100" DataFormatString="{0:0,0 (VND)}">
            </asp:BoundField>
            <asp:TemplateField>
                <HeaderTemplate>Thao Tác</HeaderTemplate>
                <ItemTemplate>
                   <asp:LinkButton ID="LinkButton1" 
                                   CommandArgument='<%# Eval("Opp_Id") %>' 
                                   CommandName="Edit" runat="server">
                                    S&#7917;a</asp:LinkButton>
                    |
                   <asp:LinkButton ID="LinkButton2" 
                                   CommandArgument='<%# Eval("Opp_Id") %>' 
                                   CommandName="Delete" runat="server">
                                    Xóa</asp:LinkButton>
                    |
                   <asp:LinkButton ID="LinkButton3" 
                                   CommandArgument='<%# Eval("Opp_Id") %>' 
                                   CommandName="Select" runat="server">
                                    Xem Hành Động</asp:LinkButton>
                    
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" />
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" />
            </asp:TemplateField>
            
        </Columns>  
        
          <FooterStyle BackColor="#004a96" />
                <HeaderStyle BackColor="#004a96" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#004a96" ForeColor="White" HorizontalAlign="Center" />
                <RowStyle BackColor="#b4cbd5" ForeColor="Black" Font-Size= "Small" />
                <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />

                <SortedAscendingCellStyle BackColor="#FBFBF2" />
                <SortedAscendingHeaderStyle BackColor="#848384" />
                <SortedDescendingCellStyle BackColor="#EAEAD3" />
                <SortedDescendingHeaderStyle BackColor="#575357" />      
    </asp:GridView>

    <asp:HiddenField ID="hdnFldSelectedValues" runat="server" />

    <br/>

    <asp:Button ID="btnCheckBox" runat="server" Text="Xóa Cơ Hội" CssClass="bty" onclick="btnCheckBox_Click" />
     <asp:Label ID="lb_IdCheckBox" runat="server" Text=""></asp:Label>

    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" CssClass="bty" Text="Tạo Mới Cơ Hội" />
    <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    </div>
    </div>
</asp:Content>
